# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=step-ca
pkgver=0.25.0
pkgrel=1
pkgdesc="A private certificate authority (X.509 & SSH) & ACME server for secure automated certificate management, so you can use TLS everywhere & SSO for SSH."
url="https://github.com/smallstep/certificates"
arch=(loong64 x86_64)
license=(Apache)
depends=(glibc pcsclite)
makedepends=(go)
source=("$url/releases/download/v${pkgver}/step-ca_${pkgver}.tar.gz")
sha512sums=('d8f58e01a1b99a1172a04c8980eca84a50bf7b3299d882dce2a01aebf0f63584fdad3bcf582d0cdc2adf0209f8aef23bb7e062d0cccb74e11a90efe160686973')

prepare(){
  mkdir -p bin
}

build() {
  BUILD_DATE="$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" '+%Y-%m-%d %H:%M UTC')"
  go build \
      -trimpath \
      -buildmode=pie \
      -mod=readonly \
      -modcacherw \
      -ldflags "-linkmode external -extldflags \"${LDFLAGS}\" -X \"main.Version=${pkgver}\" -X \"main.BuildTime=${BUILD_DATE}\"" \
      -o bin ./cmd/...
}

check() {
  go test -v ./... || true
}

package() {
  install -Dm755 "bin/step-ca" "$pkgdir/usr/bin/step-ca"
}
